<?php

/**
 * Description of HtmlForm
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
class HtmlForm extends ActiveRecord {

    /**
     * The table name.
     */
    const TABLE = "html_form";

    /**
     * The articles which this panel contains.
     *
     * @var array
     */
    protected $htmlFormElements = array();

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {
        parent::__construct($fields);
        $this->fetchHtmlFormElements();
    }

    /**
     * Fetching the array of elements which are in this form.
     */
    private function fetchHtmlFormElements() {
        $this->htmlFormElements = HtmlFormElement::search($this->getId(), self::TABLE, TRUE, TRUE);
    }

    /**
     * Getter for the array of form elements.
     * 
     * @return array
     */
    public function getHtmlFormElements() {
        return $this->htmlFormElements;
    }

    /**
     * Getting HTML form parameters for passing into a view.
     *
     * @return array
     */
    public function getViewFields() {
        $viewFields = $this->getFields();

        /**
         * Form elements.
         */
        $this->fetchHtmlFormElements();
        $viewFields["html_form_elements"] = HtmlFormElement::getFieldsFromRecords($this->htmlFormElements);
        
        return $viewFields;
    }

}